public class Test {
    public static void main(String[] args) {
        int i = 1;
        int flag = 1;
        double sum = 0;         //分数用double
        for (i = 1; i <= 100; i++) {
          sum = sum + 1.0/i *flag;      //注意是分数相加，是小数，所以除号两边需要一个数字为小数，用double类型，实现正负交替，*flag
          flag = -flag;         //正负交替  1  -1
        }
        System.out.println(sum);
    }
}
